package test5.lupeng.jf.com.teamdemo.untils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.icu.text.SimpleDateFormat;
import android.os.Build;
import android.support.annotation.RequiresApi;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Callback;
import okhttp3.OkHttpClient;
import test5.lupeng.jf.com.teamdemo.bean.request.GetUserInfoBean;

/**
 * 抽取一些方法
 * Created by Administrator on 2017/7/28.
 */

public class PostMethods {
    //获取登录用户的个人信息
    public static  void getUserInfo(String userId, Callback callback){
        OkHttpClient client=new OkHttpClient();
        String url = "https://leancloud.cn:443/1.1/functions/getMeInFo";
        client.newCall(HTTPUtils.requestPost(new GetUserInfoBean(userId),url)).enqueue(callback);
    }
   //将时间戳转化为日期格式

    public static String times(long time){
       java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
        java.sql.Date curDate = new java.sql.Date(time);// 获取当前时间
        String  date = formatter.format(curDate);
        return date;
    }
    //生成二维码
    public static Bitmap generateBitmap(String content, int width, int height) {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        Map<EncodeHintType, String> hints = new HashMap<>();
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        try {
            BitMatrix encode = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
            int[] pixels = new int[width * height];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    if (encode.get(j, i)) {
                        pixels[i * width + j] = 0x00000000;
                    } else {
                        pixels[i * width + j] = 0xffffffff;
                    }
                }
            }
            return Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565);
        } catch (WriterException e) {
            e.printStackTrace();
        }
        return null;
    }






}
